<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "
 
<html>
 <head>
  <title> New Document </title>
  <meta name="Generator" content="EditPlus">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <style type="text/css">
    table, tr, td, caption{
        border:1px solid #666;
        border-collapse:collapse;
        background-color:rgb(210, 219, 236);
    }
 
    td, caption{
        font-family:'微软雅黑';
        font-size:12px;
        text-align:center;
        padding:3px 15px;
    }
 
    caption{
        border-bottom:none;
        cursor:pointer;
    }
  </style>
 
  <script type="text/javascript">
    window.onload = function(){
        // 获取table,切换按钮并对Btn添加事件
        var tab = document.getElementsByTagName('table')[0];
        tab.caption.onclick = function(){
            console.log(tab.rows);
            // 获取表格的所有行
            var trs = tab.rows;
            for(var i = 0, len = trs.length; i < len; i++){
                // 每一行都有一个cells包含该行的所有td
                // 对于每一行的第二列进行显影
                var cell = trs[i].cells[1];
                if(cell.style.display == 'none'){
                    cell.style.display = '';
                }else{
                    cell.style.display = 'none';
                }
            }
        }
    }
  </script>
 </head>
 
 <body>
  <table>
    <caption>显示/隐藏价格</caption>
    <tr>
        <td>产品</td>
        <td>价格</td>
        <td>销量</td>
    </tr>
    <tr>
        <td>A</td>
        <td>88元</td>
        <td>2</td>
    </tr>
    <tr>
        <td>B</td>
        <td>77元</td>
        <td>3</td>
    </tr>
    <tr>
        <td>C</td>
        <td>66元</td>
        <td>4</td>
    </tr>
  </table>
 </body>
</html>